﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Material.aspx.cs" Inherits=" RzCorportativo.Views.Farmacia.Material" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> 
    <script src="<%=this.ResolveUrl("~/Recursos/j/eComplete.js")%>" type="text/javascript"></script>
    <h1>
        Material
    </h1>
    <hr />
    <asp:HiddenField runat="server" ID="FornecedorId" />
    <asp:HiddenField runat="server" ID="MaterialId" />
    <asp:HiddenField runat="server" ID="TipoMaterialId" />
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="TipoMaterial" placeholder="Material"
            data-toggle="tooltip" title="Nome do material" data-placement="left" name="complete"
            value="" auto-complete="true" eid="material" requesttype="post" contenttype="application/json; charset=utf-8"
            isasync="true" length="1" datatype="json" templeted="true" onrender="getItemMedicamento"
            onerror="getErrorMedicamento" onselected="selectedItemMedicamento" />
    </div>
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="CNPJ" mask="cnpj" placeholder="CNPJ do fornecedor"
            data-toggle="tooltip" title="Cnpj Fornecedor" data-placement="left" name="complete"
            value="" auto-complete="true" eid="descricao" requesttype="post" contenttype="application/json; charset=utf-8"
            isasync="true" length="1" datatype="json" templeted="true" onrender="getItem"
            onerror="getError" onselected="selectedItem" />
        <asp:TextBox runat="server" ID="Numero" placeholder="Número do lote" data-toggle="tooltip"
            title="Número do lote" data-placement="left" />
    </div>
    <div data-spy="scroll" data-target="" data-offset="0" class="scrollspy-example">
        <asp:TextBox runat="server" ID="Valor" placeholder="Valor R$" data-toggle="tooltip"
            title="Valor R$" data-placement="left" mask="money" />
        <asp:TextBox runat="server" ID="Quantidade" placeholder="Quantidade de itens" data-toggle="tooltip"
            title="Quantidade de itens" data-placement="left" mask="number" range="7" />
    </div>
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="DataEntrega" date="true" mask="calendar" max-year='5'
            min-date='now' placeholder="Data de entrega" data-toggle="tooltip" title="Data de entrega"
            data-placement="left" />
        <asp:TextBox runat="server" ID="DataValidade" date="true" mask="calendar" max-year='5'
            min-date='now' placeholder="Data de validade" data-toggle="tooltip" title="Data de validade"
            data-placement="left" />
    </div>
    <div data-spy="scroll" data-target="" data-offset="0" class="scrollspy-example">
        <asp:Button Text="salvar" runat="server" ID="salvar" CssClass="btn btn-success" OnClick="salvar_Click" />
        <asp:Button Text="voltar" runat="server" ID="voltar" CssClass="btn btn-info" OnClientClick="return Back();"/>
    </div>
    
    <script type="text/javascript">
        function Back() {
            window.location.href = '<%=this.ResolveUrl("~/Views/Consulta/Materiais.aspx")%>';
            return false;
        }
        function getItem(ul, item) {

            var inner_html = '<a><div class="list_item_container"><div class=""><strong>Nome:</strong> ' +
                            item.Nome + '</div><div class="description"><strong>CNPJ: </strong>' +
                            item.Cnpj + '</div></div></a>';
            return $("<li style='width:350px'></li>")
            .data("item.autocomplete", item)
            .append(inner_html)
            .appendTo(ul);
        }
        function getError(e) {
            var _alert = new Alert();
            _alert.Name = "erroGeral";
            _alert.Type = AlertType.Error;
            _alert.AddMessage(e.d ? e.d : e.responseText);
            _alert.Show();
        }

        function sourceError(e) {
            var _alert = new Alert();
            _alert.Name = "erroGeral";
            _alert.Type = AlertType.Error;
            _alert.AddMessage(e.d ? e.d : e.responseText);
            _alert.Show();

        }
        function selectedItem(event, ui, context) {
            var item = ui.item && ui.item.value ? ui.item : context;
            if (item.FornecedorId) {
                $("input[id$='FornecedorId']").val(item.FornecedorId.toString(10))
            }
        }


        function getItemMedicamento(ul, item) {

            var inner_html = '<a><div class="list_item_container"><div class=""><strong>Nome:</strong> ' +
                            item.Descricao + '</div>';
            return $("<li style='width:350px'></li>")
            .data("item.autocomplete", item)
            .append(inner_html)
            .appendTo(ul);
        }
        function getErrorMedicamento(e) {
            var _alert = new Alert();
            _alert.Name = "erroGeral";
            _alert.Type = AlertType.Error;
            _alert.AddMessage(e.d ? e.d : e.responseText);
            _alert.Show();
        }

        function selectedItemMedicamento(event, ui, context) {
            var item = ui.item && ui.item.value ? ui.item : context;
            if (item.TipoMaterialId) {
                $("input[id$='TipoMaterialId']").val(item.TipoMaterialId.toString(10))
            }
        }
    </script>
</asp:Content>
